Skip to content

feat: add shell tab completion for bash, zsh, PowerShell and fish - #795

Open
ZheFeng7110 wants to merge 2 commits into
mcpp-community:mainfrom
ZheFeng7110:feat/shell-completion
Open

ZheFeng7110 wants to merge 2 commits into
mcpp-community:mainfrom
ZheFeng7110:feat/shell-completion

Conversation

@ZheFeng7110

Copy link
Copy Markdown
Member

Tab completion now follows mcpp's CLI definitions for commands, nested subcommands, long and short options, and built-in option values. Bash, zsh, PowerShell and fish adapters use a read-only candidate query and their native filename completion, including attached file arguments.

mcpp self completion [shell] writes scripts under <mcpp-home>/config/shell/ without initializing a toolchain or accessing the network. Normal sandbox initialization also installs the scripts. The standalone installer adds a guarded loading command to the detected shell's profile, respects custom configuration directories and quoting, and avoids duplicate entries. MCPP_NO_COMPLETION and MCPP_NO_PATH independently disable profile changes, and pinned older releases remain installable. English and Chinese installation instructions document manual activation.

Closes #794.

Validation:

  • mcpp build --jobs 1 succeeds.
  • The fresh binary runs the C++ suite with MCPP_JOBS=1 and the release profile: 150 test targets pass.
  • Shell adapter and installer E2E checks run in bash, zsh, PowerShell and fish, including an interactive zsh Tab widget.
  • Repository documentation, version pins, module wiring and workflow assertions pass.

CI requires all four shells on Linux and checks native PowerShell completion on Windows.

The fish adapter asked commandline for --tokens-expanded, a flag fish only
gained in 4.0; the completion job's Ubuntu image ships fish 3.7, where the
unknown flag left the word list empty and no candidate was produced. Ask for
--tokenize (-o), which both lines accept and whose cut-at-cursor behaviour is
the same.

The Windows PowerShell job inherits MCPP from a Git Bash environment, so the
value is /d/a/... rather than a native path and native Python resolved
D:\d\a\... . Convert that spelling before resolving the binary.
@Sunrisepeak

Sunrisepeak commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

可以尝试把这个命令补全功能在 cmdline 这个库里优化好, 这样后面直接升级版本即可使用 (mcpp / xlings 和其他使用 cmdline的库 ) , 目前 cmdline里有个初步的实现可以研究一下 核心是 各个平台适配 兼容性 通用性 和 不改变 cmdline api 通用模块 能让使用 cmdline 库的 程序天然自动带有 completion 功能 (可以很简单使用一个 app.xxx(true) 控制是否启用), 具体可以参考下面相关链接

@ZheFeng7110

Copy link
Copy Markdown
Member Author

好的。

cmdline 目前的补全功能经过分析还存在问题,我先去优化 cmdline。
分析结果见 report.md

@ZheFeng7110

Copy link
Copy Markdown
Member Author

我调查了 mcpplibs/cmdline#8 的做法,它的实现与本分支的方式不同: mcpplibs/cmdline#8 是

生成/安装时:
App 命令定义 → Bash/Fish/Zsh 专用脚本

按 Tab 时:
shell 读取命令行
  → 脚本识别子命令和选项
  → 脚本生成候选

而本分支的实现原理是

生成/安装时:
安装一份薄 shell 适配脚本

按 Tab 时:
shell 收集当前输入
  → myapp __complete ...当前参数...
  → 应用定位命令、参数和候选
  → 返回候选及控制指令
  → shell 展示候选或执行文件补全

对于 mcpp 这种子命令较复杂,并且需要动态补全(比如 mcpp add [ns.]pkg@ver,需要用到 mcpp 查找已有的包索引),我认为更适合用后者的方案(也就是目前这个 pr 采用的方案)。

所以如果要通过 cmdline 实现 mcpp 的补全功能,我认为需要修改 cmdline 的补全实现方式:可以把 mcpplibs/cmdline#8 的方案撤回,改成后者的方案(用户按下 tab -> mcpp __complete xxx -> cmdline 分析 -> 输出补全候选);也可以考虑把这两种方案都保留,让用户在自己选择方案。你认为该如何选择?

完整调查记录见 session-1dc7bc9a-74a4-4d89-8f50-22fcf47f5220.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add shell tab completion for bash, zsh, PowerShell and fish

2 participants